import db, {thingBranchModelList} from '../../database/lowDB/connectDb.js';
import {autoIncreamentKey} from '../../utils/index.js'


class thingBranchModelListModel {
    constructor() {
        this.tableName = 'thingBranchModelList';
    }


    // 根据id查询某个事项分支模块
    async getBranchModelById(id){
        return thingBranchModelList.find((item)=>item.id === id)
    }

    // 根据事项模型id查询所有分支模块
    async getBranchModelsByThingModelId(thingModelId){
        return thingBranchModelList.filter((item)=>item.thingModelId === thingModelId)
    }


    // 新增事项清单模块的分支模块  —— 单条新增
    async addThingBranchModel(thingBranchModelData){
        const {userId,roleCode,thingModelId,title} = thingBranchModelData
        thingBranchModelList.unshift({
            id:autoIncreamentKey(thingBranchModelList),
            userId,
            roleCode,
            thingModelId,
            listName:title
        })
        db.write()
        return true
    }

}   

export default new thingBranchModelListModel();